﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CHPM.PL.DesktopUI.Interfaces;
using CHPM.IC.ServiceLocator;
using CHPM.PL.DesktopUI.ServiceReference1;
using CHPM.PL.DesktopUI.UserControls;

namespace CHPM.PL.DesktopUI.Presenters
{
    public class FormPresenter : BasePresenter
    {
        IView _view;
        private NewPatientPresenter _newPatient;
        private EditPatientPresenter _editPatient;
        private MainGridPresenter _mainGridPresenter;

        public FormPresenter(IView view,IServiceLocator serviceLocator) : base(serviceLocator)
        {
            _view = view;

            if(view.GetType() == typeof(FirstForm))
            {
                ShowMainForm();
            }
        }

        public void ShowMainForm()
        {
            IMainGrid mainGridControl = new MainGridControl(_serviceLocator);
            _mainGridPresenter = new MainGridPresenter(_serviceLocator, mainGridControl);
            _mainGridPresenter.PresentMainGrid(_view.AsControl);
        }

        public void ShowAddNewPatient()
        {
            INewPatient control = new EditPatient(true);
            control.formPresenter = this;
            _newPatient = new NewPatientPresenter(this._serviceLocator, control);
            _newPatient.PresentNewPatient(_view.AsControl);
        }

        public void ShowEditPatient()
        {
            PATIENT patient = new PATIENT();
            
            //IEditPatient control = new EditPatient(this._serviceLocator );
            IEditPatient control = new EditPatient();
            control.formPresenter = this;
            _editPatient = new EditPatientPresenter(this._serviceLocator, control, _mainGridPresenter.GetSelectedItem());
            _editPatient.PresentEditPatient(_view.AsControl);
        }
    }
}
